package com.huanglj.himalaya.views;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.huanglj.himalaya.R;

public class ComfirmDialog extends Dialog implements View.OnClickListener {

    private TextView mCancelBtn;
    private TextView mGiveUpBtn;
    private OnDialogClickListener mListener;
    private TextView mDialogText;

    public ComfirmDialog(@NonNull Context context) {
        this(context,0);
    }

    public ComfirmDialog(@NonNull Context context, int themeResId) {
        this(context, true,null);
    }

    protected ComfirmDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_confirm);
        initView();
        initEvent();
    }

    private void initEvent() {
        mCancelBtn.setOnClickListener(this);
        mGiveUpBtn.setOnClickListener(this);
    }

    private void initView() {
        mCancelBtn = findViewById(R.id.dialog_cancel);
        mGiveUpBtn = findViewById(R.id.dialog_give_up);
        mDialogText = findViewById(R.id.dialog_text);

    }
    public void setText(String[] text){
        mDialogText.setText(text[0]);
        mCancelBtn.setText(text[1]);
        mGiveUpBtn.setText(text[2]);
    }

    @Override
    public void onClick(View v) {
     switch (v.getId()){
         case R.id.dialog_cancel:
            mListener.cancelClick();
            dismiss();
             break;
         case R.id.dialog_give_up:
             mListener.giveUpClick();
             dismiss();
             break;
     }
    }

    public void setOnDialogClickListener(OnDialogClickListener listener){
        mListener = listener;
    }
    public interface OnDialogClickListener{
        void cancelClick();
        void giveUpClick();
    }
}
